package com.ansys.demo.controller;

import com.ansys.demo.bean.IdSum;
import com.ansys.demo.bean.Problem;
import com.ansys.demo.service.IdSumService;
import com.ansys.demo.service.QuestionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Author: panghai
 * @Date: 2022/04/05/13:21
 * @Description: 题目接口
 */
@RestController
public class QuestionController {

    @Autowired
    private QuestionService questionService;

    @Autowired
    private IdSumService idSumService;

    @GetMapping("index")
    public String index() {
        return "index";
    }

    /**
     * 获取随机题目和当前题目做题
     *
     * @return 题目列表和
     */
    @GetMapping("getQuestions")
    public Object getQuestions() {
        Map<String, Object> map = new HashMap<String, Object>();
        List<Problem> problemList = questionService.getRandomQuestions();
        List<IdSum> idSumList = idSumService.getIdSumList();
        map.put("questionList", problemList);
        map.put("idSum", idSumList);
        return map;
    }

    /**
     * 上传答题情况（上传做对题目数即可）
     * @param num 做对题目数
     * @return 上传结果
     */
    @GetMapping("/uploadTopic")
    public int uploadTopic(int num){
        return idSumService.uploadTopic(num);
    }

}
